<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" layout:decorate="main"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head>
    <title>角色添加</title>
    <link th:href="@{/localcss/crmlist.css}" href="../static/localcss/crmadd.css" rel="stylesheet">
</head>
<body>
<div layout:fragment="content">
    <div class="">
        <div class="clearfix"></div>
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>新增角色信息 <i class="fa fa-user"></i></h2>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <form class="form-horizontal form-label-left" th:action="@{/role/save}"
                              action="/role/save"
                              method="post">
                            <div id="role" class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="roleName"> 角色名称 <span
                                        class="required">*</span>
                                </label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <input id="roleName" class="form-control col-md-7 col-xs-12"
                                           data-validate-length-range="10" data-validate-words="1" name="roleName"
                                           required="required"
                                           placeholder="请输入角色名" type="text">
                                </div>
                            </div>
                            <hr>
                            <div id="users_div">

                            </div>

                            <div class="form-group">
                                <div class="col-md-6 col-md-offset-3">
                                    <button id="send" type="submit" class="btn btn-success">保存</button>
                                    <button type="button" class="btn btn-primary" id="back">返回</button>
                                    <button type="button" class="btn btn-primary" id="addUser">新增用户</button>
                                    <br/><br/>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script layout:fragment="js">

    $(document).ready(function () {
        $("#back").on("click", function () {
            window.history.back();
        });

        $(document).on("click", "[name='deluser']", function () {
            $(this).parent().parent().parent().remove();
        });

        var i = 0;
        $("#addUser").click(function () {
            console.log(i);
            var str = "<div>\n" +
                "                                    <div class=\"item form-group\">\n" +
                "                                        <label class=\"control-label col-md-3 col-sm-3 col-xs-12\"> 用户名 <span\n" +
                "                                                class=\"required\">*</span>\n" +
                "                                        </label>\n" +
                "                                        <div class=\"col-md-6 col-sm-6 col-xs-12\">\n" +
                "                                            <input class=\"form-control col-md-7 col-xs-12\"\n" +
                "                                                   data-validate-length-range=\"10\" data-validate-words=\"1\"\n" +
                "                                                   name=\"users[" + i + "].usrName\"\n" +
                "                                                   required=\"required\"\n" +
                "                                                   placeholder=\"请输入用户名\" type=\"text\">\n" +
                "                                        </div>\n" +
                "                                        <label class=\"control-label col-md-1 col-sm-3 col-xs-12\">\n" +
                "                                            <button type=\"button\" name=\"deluser\" class=\"btn btn-primary\">\n" +
                "                                                删除\n" +
                "                                            </button>\n" +
                "                                        </label>\n" +
                "                                    </div>\n" +
                "                                    <div class=\"item form-group\">\n" +
                "                                        <label class=\"control-label col-md-3 col-sm-3 col-xs-12\"> 密码 <span\n" +
                "                                                class=\"required\">*</span>\n" +
                "                                        </label>\n" +
                "                                        <div class=\"col-md-6 col-sm-6 col-xs-12\">\n" +
                "                                            <input class=\"form-control col-md-7 col-xs-12\"\n" +
                "                                                   data-validate-length-range=\"10\" data-validate-words=\"1\"\n" +
                "                                                   name=\"users[" + i + "].usrPassword\"\n" +
                "                                                   required=\"required\"\n" +
                "                                                   placeholder=\"请输入密码\" type=\"password\">\n" +
                "                                        </div>\n" +
                "                                    </div>\n" +
                "                                <hr></div>"
            $(str).appendTo("#users_div");
            i++;
        })
    });
</script>
</html>